<template>
	<view :style="{height: wh +'px'}" class="page">
		<uni-table ref="table" :loading="loading" border stripe type="selection" emptyText="暂无更多数据"
			@selection-change="selectionChange">
			<uni-tr>
				<uni-th width="50" align="center" @click="doFilter('num')">序号</uni-th>
				<uni-th width="100" align="center" @click="doFilter('commodityName')">药品名</uni-th>
				<uni-th width="180" align="center" @click="doFilter('dosage')">用量</uni-th>
				<uni-th width="90" align="center" @click="doFilter('usageName')">用法</uni-th>
				<uni-th width="90" align="center" @click="doFilter('specification')">规格</uni-th>
				<uni-th width="180" align="center" @click="doFilter('createTime')">开方时间</uni-th>
				<uni-th width="90" align="center" @click="doFilter('medicineCategoryName')">药品分类</uni-th>
				<uni-th width="120" align="center" @click="doFilter('prescriptionTime')">领药时间</uni-th>
				<uni-th width="90" align="center" @click="doFilter('remark')">备注</uni-th>
			</uni-tr>
			<uni-tr v-for="(item, index) in MedicationsList" :key="item.id">
				<uni-td>
					<view>
						{{ index + 1}}
					</view>
				</uni-td>
				<uni-td>
					<view>
						{{ item.commodityName }}
					</view>
				</uni-td>
				<uni-td align="center">{{ item.dosage }}</uni-td>
				<uni-td>
					{{item.usageName}}
				</uni-td>
				<uni-td>
					{{item.specification}}
				</uni-td>
				<uni-td>
					<view>
						{{ item.createTime }}
					</view>
				</uni-td>
				<uni-td>
					{{item.medicineCategoryName}}
				</uni-td>
				<uni-td>
					{{item.prescriptionTime}}
				</uni-td>
				<uni-td>
					{{item.remark || '无'}}
				</uni-td>
			</uni-tr>
		</uni-table>
	</view>
</template>

<script>
	import {
		getMedicationsApi,
	} from '../../common/api/user.js'

	export default {
		data() {
			return {
				MedicationsList: [],
				pageNum: 1,
				isloading: false,
				finish: false
			};
		},
		onLoad() {
			this.getMedications()
		},
		methods: {
			async getMedications() {
				this.isloading = true
				const r = await getMedicationsApi(this.pageNum)
				if (!r.data.records.length) {
					this.finish = true
				}
				this.MedicationsList.push(...r.data.records)
				this.isloading = false
			}
		},
		onReachBottom() {
			if (this.finish) return uni.$showToast('已经到底啦');
			if (this.isloading) return uni.$showToast('请求加载中');
			this.pageNum = this.pageNum + 1
			this.getMedications()
		}
	}
</script>

<style lang="scss" scoped>
</style>
